<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
	<th:block th:include="include :: header('采购单审核')" />
	<th:block th:include="include :: datetimepicker-css" />
	<th:block th:include="include :: bootstrap-fileinput-css"/>
</head>
<body class="white-bg" >
	<form class="form-horizontal m-t"  id="signupForm" th:object="${appFrom}">
		<input class="form-control" type="hidden"  name="taskId" th:value="${taskId}"/>
		<input class="form-control" type="hidden" id="processInstanceId"  th:value="${processInstanceId}"/>

		<input class="form-control" type="hidden"  name="businessKey" th:value="${appFrom.orderNo}"/>
		<input name="id" th:value="${appFrom.id}" type="hidden">
		<h2 class="form-header h2" align="center" >采购单信息</h2>
		<br/>
		<div class="form-group">
			<label class="col-sm-3 control-label">订单号：</label>
			<div class="col-sm-8">
				<input name="orderNo" th:field="*{orderNo}" class="form-control" type="text" readonly>
			</div>
		</div>
		<div class="form-group">
			<label class="col-sm-3 control-label">采购标题：</label>
			<div class="col-sm-8">
				<input name="title" th:field="*{title}" class="form-control" type="text"  required>
			</div>
		</div>
		<div class="form-group">
			<label class="col-sm-3 control-label">供应商：</label>
			<div class="col-sm-8">
				<input name="supplierName" th:field="*{supplierName}" class="form-control" type="text" >
			</div>
		</div>
		<div class="form-group">
			<label class="col-sm-3 control-label">订货日期：</label>
			<div class="col-sm-8">
				<div class="input-group date">
					<input name="orderTime" th:value="${#dates.format(appFrom.orderTime, 'yyyy-MM-dd')}" class="form-control" placeholder="yyyy-MM-dd" type="text">
					<span class="input-group-addon"><i class="fa fa-calendar"></i></span>
				</div>
			</div>
		</div>
		<div class="form-group">
			<label class="col-sm-3 control-label">交货日期：</label>
			<div class="col-sm-8">
				<div class="input-group date">
					<input name="deliveryDate" th:value="${#dates.format(appFrom.deliveryDate, 'yyyy-MM-dd')}" class="form-control" placeholder="yyyy-MM-dd" type="text">
					<span class="input-group-addon"><i class="fa fa-calendar"></i></span>
				</div>
			</div>
		</div>

		<div class="form-group">
			<label class="col-sm-3 control-label">采购人：</label>
			<div class="col-sm-8">
				<input name="belongUser" th:field="*{belongUser}" class="form-control" type="text">
			</div>
		</div>
		<h4 class="form-header h4">采购单明细信息</h4>
		<div class="row">
			<div class="col-sm-11 col-sm-offset-1">
				<button type="button" class="btn btn-success btn-sm" onclick="addColumn()"><i class="fa fa-plus"> 增加</i></button>
				<button type="button" class="btn btn-warning btn-sm" onclick="sub.delColumn()"><i class="fa fa-minus"> 删除</i></button>
				<div class="col-sm-11 select-table table-striped">
					<table id="bootstrap-table"></table>
				</div>
			</div>
		</div>
		<th:block th:include="include :: approvalpage" />
	</form>
    <th:block th:include="include :: footer" />
	<th:block th:include="include :: bootstrap-fileinput-js"/>
	<th:block th:include="include :: datetimepicker-js" />
    <script th:inline="javascript">
        var files=new Array();
        $(function () {
            var processInstanceId= $("#processInstanceId").val();
            var url ="/modeler/getProcessDiagram?processInstanceId="+processInstanceId;
            $(".imgcode").attr("src", url);
        });
        $(".file-upload").each(function (i) {
            var val = $("input[name='" + this.id + "']").val();
            $(this).fileinput({
                'uploadUrl': '/common/upload',
                initialPreviewAsData: true,
                initialPreview: [val],
                maxFileCount: 1,
                autoReplace: true
            }).on('fileuploaded', function (event, data, previewId, index) {
                files.push({"key": data.response.fileKey,"name": data.response.fileName, "url":data.response.url});
               // $("input[name='" + event.currentTarget.id + "']").val(data.response.url)
            }).on('fileremoved', function (event, id, index) {
                $("input[name='" + event.currentTarget.id + "']").val('')
            })
            $(this).fileinput('_initFileActions');
        });
        $("input[name='orderTime']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });

        $("input[name='deliveryDate']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });
        function submitCheckHandler() {
            if ($.validate.form()) {
                var data = $("#signupForm").serializeArray();
                for(var i=0;i<data.length;i++){
                    if(data[i].name=='comment'&&(data[i].value==''||data[i].value==null)){
                        $.modal.alertError("请填写审批意见");
                        return false;
                    }
                }
                if(files!=null||files!=''){
                    for(var i=0;i<files.length;i++){
                        data.push({"name": "files["+i+"].key", "value":files[i].key});
                        data.push({"name": "files["+i+"].name", "value":files[i].name});
                        data.push({"name": "files["+i+"].url", "value":files[i].url});
                    }
                }
                console.log(data);
                $.operate.saveTab("/system/purchaseOrder/restart", data);
            }
        }
        $(function() {
            var options = {
                data: [[${appFrom.purchaseOrderItemList}]],
                pagination: false,
                showSearch: false,
                showRefresh: false,
                showToggle: false,
                showColumns: false,
                sidePagination: "client",
                columns: [{
                    checkbox: true
                },
                    {
                        field: 'index',
                        align: 'center',
                        title: "序号",
                        formatter: function (value, row, index) {
                            var columnIndex = $.common.sprintf("<input type='hidden' name='index' value='%s'>", $.table.serialNumber(index));
                            return columnIndex + $.table.serialNumber(index);
                        }
                    },
                    {
                        field: 'goodsNo',
                        align: 'center',
                        title: '货物编号',
                        formatter: function(value, row, index) {
                            var html = $.common.sprintf("<input class='form-control' type='text' name='purchaseOrderItemList[%s].goodsNo' value='%s'>", index, value);
                            return html;
                        }
                    },
                    {
                        field: 'goodsName',
                        align: 'center',
                        title: '名称',
                        formatter: function(value, row, index) {
                            var html = $.common.sprintf("<input class='form-control' type='text' name='purchaseOrderItemList[%s].goodsName' value='%s'>", index, value);
                            return html;
                        }
                    },
                    {
                        field: 'goodsSize',
                        align: 'center',
                        title: '规格',
                        formatter: function(value, row, index) {
                            var html = $.common.sprintf("<input class='form-control' type='text' name='purchaseOrderItemList[%s].goodsSize' value='%s'>", index, value);
                            return html;
                        }
                    },
                    {
                        field: 'goodsQuantity',
                        align: 'center',
                        title: '数量',
                        formatter: function(value, row, index) {
                            var html = $.common.sprintf("<input class='form-control' type='text' name='purchaseOrderItemList[%s].goodsQuantity' value='%s'>", index, value);
                            return html;
                        }
                    },
                    {
                        field: 'goodsPrice',
                        align: 'center',
                        title: '单价',
                        formatter: function(value, row, index) {
                            var html = $.common.sprintf("<input class='form-control' type='text' name='purchaseOrderItemList[%s].goodsPrice' value='%s'>", index, value);
                            return html;
                        }
                    },
                    {
                        field: 'totalPrice',
                        align: 'center',
                        title: '总价',
                        formatter: function(value, row, index) {
                            var html = $.common.sprintf("<input class='form-control' type='text' name='purchaseOrderItemList[%s].totalPrice' value='%s'>", index, value);
                            return html;
                        }
                    },
                    {
                        field: 'remark',
                        align: 'center',
                        title: '备注',
                        formatter: function(value, row, index) {
                            var html = $.common.sprintf("<input class='form-control' type='text' name='purchaseOrderItemList[%s].remark' value='%s'>", index, value);
                            return html;
                        }
                    }]
            };
            $.table.init(options);
        });
        function addColumn() {
            var row = {
                goodsNo: "",
                goodsName: "",
                goodsSize: "",
                goodsQuantity: "",
                goodsPrice: "",
                totalPrice: "",
                remark: ""
            };
            sub.addColumn(row);
        }
    </script>
</body>
</html>